program c1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;
var
  T: Word = 1;
  R: Word = 100;
  N: Word = 3;
  M: Word = 5;
  K: Word = 7;

var
  f, g: TextFile;
  answer: String;
  p: array[1..8000] of Int64;
  Max2, Max3, Max5, Max7: Int64;

procedure ReadPreliminaryData;
begin
  Readln(f, t);
  Readln(f, R, N, M, K);
end;

procedure ReadData;
var
  i: Word;
begin
  for i := 1 to K do begin
    Read(f, p[i]);
  end;
  Readln(f);
end;

function Test(x: Int64; i: byte): Int64;
begin
  Result := 0;
  while x mod i = 0 do begin
    x := x div i;
    Inc(Result);
  end;
end;

procedure ProcessData;
var
  a, i: Word;
  SumMax: Word;
begin
  Max2 := 0;
  Max3 := 0;
  Max5 := 0;
  Max7 := 0;
  for i := 1 to R do begin
    a := Test(p[i], 2);
    if a > Max2 then
      Max2 := a;
    a := Test(p[i], 3);
    if a > Max3 then
      Max3 := a;
    a := Test(p[i], 5);
    if a > Max5 then
      Max5 := a;
    a := Test(p[i], 7);
    if a > Max7 then
      Max7 := a;
  end;
  SumMax := Max2 + Max3 + Max5 + Max7;
  answer := '';
  if (SumMax = n) then begin
    for i := 1 to Max2 do
       answer := answer + '2';
    for i := 1 to Max3 do
       answer := answer + '3';
    for i := 1 to Max5 do
       answer := answer + '5';
    for i := 1 to Max7 do
       answer := answer + '7';
  end;
  if (Summax = n + 1) then begin
    for i := 1 to Max2 div 2 do
       answer := answer + '4';
    for i := 1 to Max3 do
       answer := answer + '3';
    for i := 1 to Max5 do
       answer := answer + '5';
    for i := 1 to Max7 do
       answer := answer + '7';
  end;
  if (Summax > n + 1) then
    answer := 'Error';
  if (Summax = 0) then
    for i := 1 to n do
      answer := answer + IntToStr(Random(m - 2) + 2);
end;


procedure OutputVerdict(casenum: Word);
begin
  writeln(g, 'Case #', casenum, ':');
end;

procedure OutputSubVerdict;
begin
  writeln(g, answer);
end;


var
  i, j: Word;
  s: String;
begin
  try
    s := ParamStr(1);
    if (s = '') then
       s := 'input.txt';
    AssignFile(f, s);
    Reset(f);
    AssignFile(g, 'output.txt');
    Rewrite(g);
    try
      ReadPreliminaryData;
      for i := 1 to t do begin
        OutputVerdict(i);
        for j := 1 to R do begin
          ReadData;
          ProcessData;
          OutputSubVerdict;
        end;

      end;
    finally
      CloseFile(f);
      CloseFile(g);
    end;
    writeln('Reading finished');
    Readln;
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E: Exception do begin
      Writeln(E.ClassName, ': ', E.Message);
      readln;
    end;
  end;
end.
